"""
查询相关方法
"""
import operator


def usage():
    print("usage --------------------")
    nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]

    # 元素次数
    print("count "+ str(nums.count(0)))

    #元素长度 函数
    print("len "+str(len(nums)))

    #min 函数
    print("min "+str(min(nums)))
    #max 函数
    print("max " + str(max(nums)))



    #重复
    print([0, 1] * 3)


    #元素是否存在于列表中
    print(-1 in [0, 1, 2, 3])

    #元组转换为列表
    tuple1=(0,1,2,3,"4","5")
    print(list(tuple1))

    pass

"""
    查询相关
"""
def query():
    print("query --------------------")
    nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]
    print(nums[:])
    print(nums[0:999])
    print(nums[0])
    #获取倒数第二个下标的数据
    print(nums[-2])
    # right 只能比left 大
    print(nums[-2:-1])
    pass

"""
删除相关方法
"""


def remove():
    print("remove --------------------")
    nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]
    # 删除第一个指定元素 非下标 值不存在则会ValueError 太坑了
    nums.remove(1)
    print(nums)

    # 删除指定下标 元素
    del nums[0]
    print(nums)

    # 删除并返回指定下标元素
    print(nums.pop(0))
    print(nums)

    pass


def fors():
    print("for --------------------")
    nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]
    # for x in nums:
    #     print(x)

    #PEP 8: E701 multiple statements on one line (colon)
    for x in nums: print(x)

    pass

def add():
    print("add --------------------")
    nums = ["9", 8, "7", 6, "5", 4, "3", 2, "1"]

    # 追加元素
    nums.append(0)
    print(nums)


    #insert
    nums.insert(0,10)
    print(nums)

    # 合并列表1
    num2s = [-1, -2, "-3"]
    num3s = num2s + nums
    print(num3s)

    # 合并列表2
    print(num3s.append([1, 2, "3"]))

    pass

# 类似Java中的数组
if __name__ == '__main__':
    usage()
    #add()
   # query()
    #remove()
    # fors()
    pass
